﻿using UnityEngine;
using System.Collections;

public class TestEventDispatcher : MonoBehaviour
{
    

    // Use this for initialization
    void Start()
    {
        EventNotificationDispatcher.Instance.Register<MainRoleLevel>(OnRoleLevelChanged);
        EventNotificationDispatcher.Instance.Register<Person>(StrutParmetTest);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            EventNotificationDispatcher.Instance.Publish(null, new MainRoleLevel(null,Random.Range(1,100)));
            EventNotificationDispatcher.Instance.Publish(null, new Person("wuzhang"));
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            EventNotificationDispatcher.Instance.UnRegister<MainRoleLevel>(OnRoleLevelChanged);
        }
    }

    /// <summary>
    /// 注册角色等级变化处理事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="evt"></param>
    private void OnRoleLevelChanged(object sender, MainRoleLevel evt)
    {
        Debug.Log(evt.level);
    }

    public void StrutParmetTest(object sender, Person p)
    {
        Debug.Log(p.name);
    }

}
